package cn.dbwork.yacht.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.dbwork.yacht.domain.User;
import cn.dbwork.yacht.service.IUserService;
import cn.dbwork.yacht.service.impl.UserService;

@WebServlet("/register.do")
public class RegisterServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public RegisterServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		IUserService userService=new UserService();

		String account = request.getParameter("account");
		String password = request.getParameter("password");
		String name = request.getParameter("name");
		String sex = request.getParameter("sex");
		Integer age = Integer.parseInt(request.getParameter("age"));
		String tel = request.getParameter("tel");
		
		User user = new User();
		user.setAccount(account);
		user.setPassword(password);
		user.setName(name);
		user.setSex(sex);
		user.setAge(age);
		user.setTel(tel);
		
		userService.memNew(user);
		
		if(userService.checkFromTel(user.getTel())==0) {
			user=userService.findStuAndPass(account, password);
			request.getSession().setAttribute("session_user", user);
			request.getSession().setAttribute("LoginInfo","注册成功");
			System.out.println("===========跳转主页面================");
			//return "main";
			request.getRequestDispatcher("WEB-INF/pages/main.jsp").forward(request, response);
		
		  }else {
		  
		  }
		 
		}
			
}


